class Sales::InvoicesController < ApplicationController
  before_action :set_sales_invoice, only: [:show, :edit, :update, :destroy]

  # GET /sales/invoices
  # GET /sales/invoices.json
  def index
    @sales_invoices = Sales::Invoice.all
  end

  # GET /sales/invoices/1
  # GET /sales/invoices/1.json
  def show
  end

  # GET /sales/invoices/new
  def new
    @sales_invoice = Sales::Invoice.new
  end

  # GET /sales/invoices/1/edit
  def edit
  end

  # POST /sales/invoices
  # POST /sales/invoices.json
  def create
    @sales_invoice = Sales::Invoice.new(sales_invoice_params)

    respond_to do |format|
      if @sales_invoice.save
        format.html { redirect_to @sales_invoice, notice: 'Invoice was successfully created.' }
        format.json { render :show, status: :created, location: @sales_invoice }
      else
        format.html { render :new }
        format.json { render json: @sales_invoice.errors, status: :unprocessable_entity }
      end
    end
  end

  # PATCH/PUT /sales/invoices/1
  # PATCH/PUT /sales/invoices/1.json
  def update
    respond_to do |format|
      if @sales_invoice.update(sales_invoice_params)
        format.html { redirect_to @sales_invoice, notice: 'Invoice was successfully updated.' }
        format.json { render :show, status: :ok, location: @sales_invoice }
      else
        format.html { render :edit }
        format.json { render json: @sales_invoice.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /sales/invoices/1
  # DELETE /sales/invoices/1.json
  def destroy
    @sales_invoice.destroy
    respond_to do |format|
      format.html { redirect_to sales_invoices_url, notice: 'Invoice was successfully destroyed.' }
      format.json { head :no_content }
    end
  end

  private
    # Use callbacks to share common setup or constraints between actions.
    def set_sales_invoice
      @sales_invoice = Sales::Invoice.find(params[:id])
    end

    # Never trust parameters from the scary internet, only allow the white list through.
    def sales_invoice_params
      params.require(:sales_invoice).permit(:firm_id, :order_id, :finance_info_id, :created_by, :invoice_money, :invoice_type, :invoice_num, :invoice_date, :notes)
    end
end
